package utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * RabbitMQ连接工具
 * 
 * @author liuxing
 *
 */
public class ConnectionUtils {

	/**
	 * 获取RabbitMQ的连接
	 * 
	 * @return
	 * @throws Exception
	 */
	public static Connection getMQConnection() throws Exception {
		ConnectionFactory factory = new ConnectionFactory();
//		factory.setHost("192.168.0.222"); // RabbitMQ所在的客户端
		factory.setHost("10.37.129.51"); // RabbitMQ所在的客户端
		factory.setPort(5672);// 设置RabbitMQ的端口号，默认为5672
		factory.setVirtualHost("/messagemgr"); // 设置虚拟主机路径
		factory.setUsername("liuxing"); // 设置用户名
		factory.setPassword("liuxing");// 设置密码
		Connection connection = factory.newConnection(); // 获取连接
		return connection;
	}
}
